//
//  LimitFreeUtility.m
//  LimitFree
//
//  Created by lijinghua on 16/3/1.
//  Copyright © 2016年 lijinghua. All rights reserved.
//

#import "LimitFreeUtility.h"

@implementation LimitFreeUtility

+ (NSString*)calculateDiffTimeToDate:(NSString*)expireDate
{
    //1:把输入的字符串日期转换为NSDate日期
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    //指定日期格式
    dateFormat.dateFormat = @"yyyy-MM-dd HH:mm:ss.0";
    NSDate *toDate = [dateFormat dateFromString:expireDate];
    //2:获取当前的时间
    NSDate *fromDate = [NSDate date];
    //3:使用日历控件计算差值
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger flag = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    //使用components 计算2个日期的差值,返回的对象中包含他们的差
    NSDateComponents *compoent = [calendar components:flag fromDate:fromDate toDate:toDate options:0];
    //4:格式化输出
    return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",compoent.hour,compoent.minute,compoent.second];
}

@end
